<?php
/**
 * GeoContexter
 * @link http://code.google.com/p/geocontexter/
 * @package GeoContexter
 */

/**
 * user main controller
 *
 * @package GeoContexter
 * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
 * @author Armand Turpel <geocontexter@gmail.com>
 * @version $Rev: 828 $ / $LastChangedDate: 2011-02-27 10:30:28 +0100 (So, 27 Feb 2011) $ / $LastChangedBy: armand.turpel $
 */

namespace Geocontexter\Controller;

use Zend\View\Model\ViewModel;
use Core\Controller\AbstractController;

class UserController extends AbstractController
{
    public function init()
    {
        $this->initView( 'geocontexter/user/index.phtml' );

        // prepend to page title
        //
        $this->renderer->headTitle('List users', 'PREPEND');

        $this->view->partialData = array('active_page' => 'main');
    }

    public function indexAction()
    {
        $params = array();

        $id_group = $this->params()->fromRoute('id_group',false);

        if ($id_group !== false) {
          $this->view->id_group = $id_group;
          $params['id_group'] = (int)$id_group;
        }

        $id_status = $this->params()->fromRoute('id_status',false);

        if ($id_group !== false) {
          $this->view->id_status = $id_status;
          $params['id_status']   = (int)$id_status;
        }

        $UserGetUsers = $this->CoreModel('UserGetUsers');

        $result = $UserGetUsers->run( $params );

        $this->view->users_result   = $result;
        $this->view->total_num_rows = $UserGetUsers->totalNumRows();

        if ($result instanceof \Core\Library\Exception) {
           return $this->error( $result->getMessage(), __file__, __line__);
        }

        return $this->view;
    }
}
